Skip to content

base_parser: support relative path include files#399

Open
Javagedes wants to merge 4 commits intotianocore:masterfrom
Javagedes:bugfix-base_parser
Open

base_parser: support relative path include files#399
Javagedes wants to merge 4 commits intotianocore:masterfrom
Javagedes:bugfix-base_parser

Conversation

@Javagedes
Copy link
Copy Markdown
Contributor

@Javagedes Javagedes commented Aug 28, 2023

This commit adds support for including multiple relative paths from the same directory by storing a stack of all included files that have not finished being parsed, and the number of lines that still need to be parsed in each file.

Previously, only includes of nested relative paths were supported as the currently parsed file was not reverted to the previous file when the parsing of an included file was completed. This led to further includes needing the be relative to the latest included file.

closes #394

@Javagedes Javagedes requested a review from spbrogan August 28, 2023 18:41
@Javagedes Javagedes added this to the v0.17.1 milestone Aug 28, 2023
@codecov
Copy link
Copy Markdown

codecov bot commented Aug 28, 2023

Codecov Report

❌ Patch coverage is 96.96970% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 81.30%. Comparing base (cadd3f2) to head (d15392b).
⚠️ Report is 203 commits behind head on master.

Files with missing lines Patch % Lines
edk2toollib/uefi/edk2/parsers/base_parser.py 94.11% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #399      +/-   ##
==========================================
+ Coverage   81.19%   81.30%   +0.11%     
==========================================
  Files          57       57              
  Lines        7358     7383      +25     
==========================================
+ Hits         5974     6003      +29     
+ Misses       1384     1380       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Javagedes Javagedes modified the milestones: v0.18.1, 0.18.3 Oct 2, 2023
@Javagedes Javagedes modified the milestones: 0.19.1, 0.19.2, 0.19.3, 0.19.4 Oct 23, 2023
@Javagedes Javagedes modified the milestones: 0.19.4, 0.19.5 Nov 1, 2023
@Javagedes Javagedes modified the milestones: 0.19.5, 0.19.6, v0.19.7 Nov 20, 2023
@Javagedes Javagedes modified the milestones: 0.19.7, 0.19.8 Dec 4, 2023
@Javagedes Javagedes requested a review from makubacki December 8, 2023 19:39
This commit adds support for including multiple relative paths from
the same directory by storing a stack of all included files that have
not finished being parsed, and the number of lines that still need to
be parsed in each file.

Previously, only includes of nested relative paths were supported as
the currently parsed file was not reverted to the previous file when the
parsing of an included file was completed. This led to further includes
needing the be relative to the latest included file.
@Javagedes Javagedes modified the milestones: 0.19.8, v0.19.9 Dec 13, 2023
@Javagedes Javagedes modified the milestones: v0.19.9, v0.19.10 Jan 11, 2024
@Javagedes Javagedes modified the milestones: v0.20.2, v0.20.3, v0.20.4 Feb 9, 2024
self.PPs = []
self._Edk2PathUtil = None
self.TargetFilePath = None # the abs path of the target file
self.FilePathStack = [] # a stack containing a list of size 2: [filepath, line_count]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT:

Since you're likely dealing with a large set of data, the following solution probably doesn't make a lot of sense performance wise but if you wanted to improve readability of the code you could do something like a namedtuple.

However the object instantiation might be too much for a large dataset

from collections import namedtuple

# Define the namedtuple type
FilePathRecord = namedtuple('FilePathRecord', ['filepath', 'line_count'])

self.FilePathStack = []  # a stack containing FilePathRecord instances

self.FilePathStack.append(FilePathRecord('my_file_path', 100))

self.FilePathStack[0].file_path

return False
line_count = self.FilePathStack[-1][1]
if line_count - 1 > 0:
self.FilePathStack[-1][1] -= 1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT:

        updated_line_count = self.FilePathStack[-1][1] - 1
        if updated_line_count > 0:
            self.FilePathStack[-1][1] -= updated_line_count

raise FileNotFoundError(include_file)
self.Logger.debug("Opening Include File %s" % sp)
self._PushTargetFile(sp)
lf = open(sp, "r")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: I know you didn't write this but if we switch to with we can drop lf.close()

@Javagedes Javagedes modified the milestones: v0.21.4, v0.21.6 Apr 15, 2024
@Javagedes Javagedes modified the milestones: v0.21.6, v0.21.7, v0.21.8 Jun 5, 2024
@Javagedes Javagedes modified the milestones: v0.21.8, v0.21.9 Jun 24, 2024
@Javagedes Javagedes modified the milestones: v0.21.9, v0.21.10, v0.21.11 Jul 31, 2024
@Javagedes Javagedes modified the milestones: v0.21.11, v0.21.12, v0.21.13 Oct 1, 2024
@Javagedes Javagedes modified the milestones: v0.22.0, v0.22.1, v0.22.2, v0.22.3 Oct 14, 2024
@Javagedes Javagedes modified the milestones: v0.22.3, v0.22.4 Nov 22, 2024
@Javagedes Javagedes removed this from the v0.22.4 milestone Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: base_parser.TargetFilePath not reverted when exiting an !include parse

2 participants